<?php
// No direct access
defined('_JEXEC') or die;

/**
 * BP Syntax Highlighter Controller - Joomla component primary controller class mantaing 
 * administrative features for managing code snippers.
 *
 * @package		Joomla.Administrator
 * @subpackage	com_bpsyntaxhighlighter
 */
class BPSyntaxHighlighterController extends JController
{
	/**
	* @var		string	The default view.
	* @since	1.6
	*/
	protected $default_view = 'snippets';
	
	/**
	 * Method to display a view.
	 *
	 * @param	boolean			$cachable	If true, the view output will be cached
	 * @param	array			$urlparams	An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
	 *
	 * @return	JController		This object to support chaining.
	 */	
	public function display($cachable = false, $urlparams = false)
	{
		JLoader::register('BPSyntaxHighlighterHelper', JPATH_COMPONENT.'/helpers/bpsyntaxhighlighter.php');

		BPSyntaxHighlighterHelper::addSubmenu(JRequest::getCmd('view', 'snippets'));

		$view = JRequest::getCmd('view', 'snippets');
		$layout	= JRequest::getCmd('layout', 'default');
		$id = JRequest::getInt('id');

		if ($view == 'snippet' && $layout == 'edit' && !$this->checkEditId('com_bpsyntaxhighlighter.edit.snippet', $id)) {
				$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
			$this->setMessage($this->getError(), 'error');
			$this->setRedirect(JRoute::_('index.php?option=com_bpsyntaxhighlighter&view=snippets', false));	
			return false;
		}
		
		parent::display();
		return $this;
	}
}